home *** CD-ROM | disk | FTP | other *** search
- /* Small Systems Guild */
-
- /* copyright © 1987 Small Systems Guild */
- /* Lightspeed C compiler 2.01 */
-
- /* private library source file */
-
- /* DAS 02/10/87 Created this file, added SetShell() 0.1 */
- /* DAF 02/11/87 Added CountWindows(), DoDlog(), ZoomRect(), 0.2 */
- /* GlobalCellRect(), */
- /* DAS 02/16/87 Fixed ZoomRect() globalism bug 0.3 */
- /* DAF 03/05/87 Added app launch list support routines, structs 0.4 */
- /* DAF 03/09/87 Added WDPBRec definition, restructured LaunchInfo 0.5 */
-
- #include <interchange.h>
-
- int ByteCopy(toPtr,fromPtr,count)
- char *toPtr,*fromPtr;
- int count;
- {
- int i,bytes = 0;
-
- for (i = 0;i < count;i++) {
- toPtr[i] = fromPtr[i];
- bytes++;
- }
- return(bytes);
- }
-
- Boolean SetShell(progName)
- char *progName;
- {
- int charCount,i;
- char *shellBuff;
-
- charCount = (unsigned char)(progName[0]);
- if ((charCount > SHELLmaxname) || (charCount == 0))
- return(FALSE);
-
- /* should really check for an application with this name... */
- /* but that's too tough, for now! */
-
- shellBuff = (char *)FinderName;
- for (i=0; i<=charCount; i++)
- *shellBuff++ = *progName++;
- for ( ; i<=SHELLmaxname; i++)
- *shellBuff++ = ' ';
-
- return(TRUE);
- }
-
- int DoDlog(dialogNum,topItem)
- int dialogNum,topItem;
- {
- DialogPtr DP;
- Handle H;
- int i = 0;
-
- H = GetResource('DLOG',dialogNum);
- if ((!ValidHandle((Handle)H)) || (ResError() != noErr))
- return(0);
-
- DP = GetNewDialog(dialogNum,NULL,NEG_ONE); /* read dialog from resource fork */
- if ((ResError() == noErr) && ValidPointer((Ptr)DP)) { /* dialog found */
- ShowWindow(DP); /* make sure dialog window is made visible */
- FrameDItem(DP,1);
- do {
- ModalDialog(NULL,&i); /* loop in Dialog manager until item hit */
- CheckDItem(DP,i);
- } while (i == 0 || i > topItem);
- DisposDialog(DP); /* throw away dialog, reclaim memory */
- return(i); /* return dialog item number selected */
- }
- else
- return(0); /* dialog not found in open resource forks */
- }
-
- void ZoomRect(aWindow,aRect,direction)
- WindowPtr aWindow;
- Rect *aRect;
- Boolean direction;
- {
- Rect wRect;
-
- if (!ValidPointer((Ptr)aWindow) || !ValidPointer((Ptr)aRect))
- RETURN;
- wRect = aWindow->portRect;
- LocalToGlobal(&(topLeft(wRect))); /* global coordinates for rectangle */
- LocalToGlobal(&(botRight(wRect)));
-
- if (direction) {
- Telescope(aRect,&wRect,16);
- ShowWindow(aWindow);
- SelectWindow(aWindow);
- }
- else {
- Telescope(&wRect,aRect,16);
- }
- }
-
- void GlobalCellRect(aWindow,list,cell,theRect)
- WindowPtr aWindow;
- ListHandle list;
- Point cell;
- Rect *theRect;
- {
- GrafPtr savePort;
- Rect iRect;
- Cell tCell;
-
- if (!ValidHandle((Handle)list))
- RETURN;
-
- LRect(&iRect,pass(cell),list);
- GetPort(&savePort);
- SetPort(aWindow);
- LocalToGlobal(&(topLeft(iRect))); /* global coordinates for rectangle */
- LocalToGlobal(&(botRight(iRect)));
- SetPort(savePort);
- *theRect = iRect;
- }
-
- int CountWindows()
- {
- WData WD;
- WindowPtr currWP;
- int howMany;
-
- currWP = FrontWindow();
- howMany = 0;
- while (ValidPointer((Ptr)currWP)) {
- GetWData(currWP,&WD);
- if (ValidWData(&WD)) {
- if (((WindowPeek)currWP)->visible) {
- howMany++;
- }
- }
- currWP = (WindowPtr)(((WindowPeek)currWP)->nextWindow);
- }
- return(howMany);
- }
-
- WindowPtr InsertWindow(wrPtr,place,wRect,Title,wType,Visible,GoAwayBox,GrowBox,vScrollBar,hScrollBar)
- WindowRecord *wrPtr;
- WindowPtr place;
- Rect *wRect;
- char *Title;
- int wType;
- Boolean Visible,GoAwayBox,GrowBox,vScrollBar,hScrollBar;
- {
- WData WD;
- WDHandle tempWDH;
- WindowPtr oldFrontW;
- Rect boundsRect;
-
- boundsRect = *wRect;
- if ((wType < 0) || (wType > 23) ||
- ((wType > 4) && (wType < 16) && (wType != 8) && (wType != 12)))
- return(NULL);
- /* make conflicting window types consistent */
- if ((GrowBox == FALSE) && (wType == 0))
- wType = 4;
- if ((GrowBox != FALSE) && (wType == 4))
- wType = 0;
- if ((GrowBox == FALSE) && (wType == 8))
- wType = 12;
- if ((GrowBox != FALSE) && (wType == 12))
- wType = 8;
-
- oldFrontW = FrontWindow();
-
- wrPtr = (WindowRecord *)NewWindow(wrPtr,&boundsRect,Title,FALSE,wType,place,GoAwayBox,NULL);
- if (!ValidPointer((Ptr)wrPtr))
- return(NULL);
-
- InitWData(&WD);
- WD.GrowBox = GrowBox;
- if (GrowBox)
- DrawGrowIcon(wrPtr);
- if (vScrollBar) {
- boundsRect.left = ((WindowPtr)wrPtr)->portRect.right - XTBarWidth;
- boundsRect.top = ((WindowPtr)wrPtr)->portRect.top - 1;
- boundsRect.right = ((WindowPtr)wrPtr)->portRect.right + 1;
- boundsRect.bottom = ((WindowPtr)wrPtr)->portRect.bottom -
- ((WindowPtr)wrPtr)->portRect.top;
- if (GrowBox)
- boundsRect.bottom -= 14;
- WD.vScrollBar = NewControl(wrPtr,&boundsRect,"\P",Visible,1,1,100,scrollBarProc,NULL);
- }
- if (hScrollBar) {
- boundsRect.left = ((WindowPtr)wrPtr)->portRect.left - 1;
- boundsRect.top = ((WindowPtr)wrPtr)->portRect.bottom - XTBarWidth;
- boundsRect.right = ((WindowPtr)wrPtr)->portRect.right;
- if (GrowBox || vScrollBar)
- boundsRect.right -= 14;
- boundsRect.bottom = ((WindowPtr)wrPtr)->portRect.bottom + 1;
- WD.hScrollBar = NewControl(wrPtr,&boundsRect,"\P",Visible,1,1,100,scrollBarProc,NULL);
- }
- tempWDH = (WDHandle)NewHandle((long)sizeof(WData));
- SetWRefCon(wrPtr,tempWDH);
- if (!ValidHandle((Handle)tempWDH))
- return(NULL);
- (**tempWDH).sync1 = SYNC1VAL;
- (**tempWDH).sync2 = SYNC2VAL;
- SetWData((WindowPtr)wrPtr,&WD);
-
- if (!Visible)
- return((WindowPtr)wrPtr);
-
- ShowHide(wrPtr,TRUE);
- SetPort(wrPtr);
-
- if (ValidPointer((Ptr)oldFrontW)) {
- GetWData(oldFrontW,&WD);
- if (ValidWData(&WD)) {
- if (WD.GrowBox)
- DrawGrowIcon(oldFrontW);
- if (ValidHandle((Handle)(WD.vScrollBar)))
- HideControl(WD.vScrollBar);
- if (ValidHandle((Handle)(WD.hScrollBar)))
- HideControl(WD.hScrollBar);
- }
- }
-
- return((WindowPtr)wrPtr);
- }
-